<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Route,URL,Auth;

class CaseController extends Controller
{

  //获取当前时间
  public function time (){
       date_default_timezone_set('Asia/Shanghai');
       $time= date('Y-m-d H:i:s',time());
       return $time;
  }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $re = DB::table('cases')->orderBy('case_id','desc')->paginate(10);
        $count = DB::table('cases')->count();
        return view('admin.case.index',['re'=>$re,'count'=>$count]);
    }



    //待办案件
    public function daiban(){

      $re = DB::table('cases')->where('is_ok', '=', '0')->orWhere('is_deadline', '=', '0')->orderBy('case_id','desc')->paginate(10);

      $count = DB::table('cases')->where('is_ok', '=', '0')->orWhere('is_deadline', '=', '0')->count();
      return view('admin.case.daiban',['re'=>$re,'count'=>$count]);
    }




    //不合格录入案件
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create($id,Request $request)
    {
        //
        if($request->isMethod('post')){
          //是否存在参数
          $input = $request->all();

            if($input['case_name']){
                $data = Input::except('_token');

                $data = array(
                    'case_name' => $input['case_name'],
                    'case_address' => $input['case_address'],
                    'case_type' => $input['case_type'],
                    'case_company' => $input['case_company'],
                    'case_area' => $input['case_area'],
                    'case_project' => $input['case_project'],
                    'case_checktime' => $input['case_checktime'],
                    'case_desc' => $input['case_desc'],
                    'created_at' =>  $this->time(),

                );


                DB::table('cases')->insert($data);


                //改变不合格已立案的状态

                $u = array(
                  'is_case' => 1,
                );
                DB::table('jiancha')->where('id',$id)->update($u);




                return redirect('admin/case/index');
            }else{
              echo "<script>alert('案件名称不能为空!');window.history.go(-1);</script>";
            }
        }

          //获取分类
          $type = DB::table('casetype')->orderBy('id','desc')->get();

          //获取单位列表
          $units = DB::table('units')->orderBy('id','desc')->get();

          //获取不合格单位信息

          $un = DB::table('jiancha')->where('jiancha.id',$id)->join('units', 'units.id', '=', 'jiancha.unit_id')->select( 'jiancha.status','jiancha.is_case','jiancha.is_del','jiancha.created_at','jiancha.unit_id','jiancha.id','units.name')->first();

          return view('admin.case.create',['type'=>$type,'units'=>$units,'un'=>$un]);

    }


      public function caseadd(Request $request)
    {
        //
        if($request->isMethod('post')){
          //是否存在参数
          $input = $request->all();

            if($input['case_name']){
                $data = Input::except('_token');

                $data = array(
                    'case_name' => $input['case_name'],
                    'case_address' => $input['case_address'],
                    'case_type' => $input['case_type'],
                    'case_company' => $input['case_company'],
                    'case_area' => $input['case_area'],
                    'case_project' => $input['case_project'],
                    'case_checktime' => $input['case_checktime'],
                    'case_desc' => $input['case_desc'],
                    'created_at' =>  $this->time(),

                );


                DB::table('cases')->insert($data);
                return redirect('admin/case/index');
            }else{
              echo "<script>alert('案件名称不能为空!');window.history.go(-1);</script>";
            }
        }

          //获取分类
          $type = DB::table('casetype')->orderBy('id','desc')->get();

          //获取单位列表
          $units = DB::table('units')->orderBy('id','desc')->get();

          return view('admin.case.caseadd',['type'=>$type,'units'=>$units]);

    }



    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id,Request $request)
    {
        //

        //获取分类和案件
        $case = DB::table('cases')->where('case_id',$id)->first();
        $type = DB::table('casetype')->orderBy('id','desc')->get();
        //获取单位列表
        $units = DB::table('units')->orderBy('id','desc')->get();

        //获取限期整改
        $hd = array(
          'case_id' => $id,
        );
        $cd = DB::table('casedeadline')->where($hd)->join('admin_users', 'casedeadline.uid', '=', 'admin_users.id')->select('casedeadline.*', 'admin_users.name')->first();





        if($request->isMethod('post')){
          //是否存在参数
          $input = $request->all();
            if($input['case_name']){
              $data = Input::except('_token');

              $data = array(
                  'case_name' => $input['case_name'],
                  'case_address' => $input['case_address'],
                  'case_type' => $input['case_type'],
                  'case_company' => $input['case_company'],
                  'case_area' => $input['case_area'],
                  'case_project' => $input['case_project'],
                  'case_checktime' => $input['case_checktime'],
                  'case_desc' => $input['case_desc'],
                  'created_at' =>  $input['created_at'],
                  'is_ok' => 1,

                  'updated_at' =>$this->time(),
              );
                  DB::table('cases')->where('case_id',$id)->update($data);
                  //跳入限期整改
                  return redirect()->back();
                  // return redirect("admin/case/no/$id");
              }else{
                echo "<script>alert('案件名称不能为空!');window.history.go(-1);</script>";
              }
        }
        return view('admin.case.edit',['type'=>$type,'case'=>$case,'units'=>$units,'cd'=>$cd]);

    }

    //期限整改
    public function no($id,Request $request)
    {
        //
        $case = DB::table('cases')->where('case_id',$id)->first();

        //获取期限
        $headline = DB::table('casedeadline')->where('case_id',$id)->first();


        if($request->isMethod('post')){
          //是否存在参数
          $input = $request->all();
            if($input['start']){
              $data = Input::except('_token');

              $data = array(
                  'start' => $input['start'],
                  'end' => $input['end'],
                  'uid' => Auth::guard('admin')->user()->id,
                  'case_id' => $id,
                  'created_at' =>$this->time(),
              );
              // $map['is_deadline'] = '1';
              // $map['is_deadlineok'] = '0';
              // DB::table('cases')->where('case_id',$id)->update($map);

              $cd =  DB::table('casedeadline')->where('case_id',$id)->first();
              if ($cd) {
                DB::table('casedeadline')->where('case_id',$id)->update($data);
              }else{
                 DB::table('casedeadline')->insert($data);
              }

              //跳入
              return redirect("admin/case/xqtong/$id");

              }else{
                echo "<script>alert('请填写开始日期!');window.history.go(-1);</script>";
              }
        }


        return view('admin.case.no',['case'=>$case,'headline'=>$headline]);

    }

    //限期通知书
    public function xqtong($id,Request $request){
       $case = DB::table('cases')->where('case_id',$id)->first();

       $headline = DB::table('casedeadline')->where('case_id',$id)->first();

       //获取单位
       $un = array(
          'id' => $case->case_address,
        );
       $unit = DB::table('units')->where($un)->select('name')->first();

       //获取组织
       $uid = array(
         'admin_users.id' => Auth::guard('admin')->user()->id,
       );
      $user = DB::table('admin_users')->where($uid)->join('org', 'admin_users.org_id', '=', 'org.id')->select('admin_users.org_id', 'admin_users.id','org.name')->first();
       return view('admin.case.xqtong',['case'=>$case,'headline'=>$headline,'unit'=>$unit,'user'=>$user]);

    }


    //警方整改通知书查看
    public function zgck($id,Request $request){
        $case = DB::table('cases')->where('case_id',$id)->first();


       $headline = DB::table('casedeadline')->where('case_id',$id)->first();

       //获取单位
       $un = array(
          'id' => $case->case_address,
        );
       $unit = DB::table('units')->where($un)->select('name')->first();

       //获取组织
       $uid = array(
         'admin_users.id' => $headline->uid,
       );

       $user = DB::table('admin_users')->where($uid)->join('org', 'admin_users.org_id', '=', 'org.id')->select('admin_users.org_id', 'admin_users.id','org.name')->first();

       //获取人员信息
       $pe = array(
          'id' =>  $headline->uid,
        );

        $pes = array(
          'id' =>  $headline->last_uid,
        );

        $peo =  DB::table('admin_users')->where($pe)->select('name')->first();
        $peos =  DB::table('admin_users')->where($pes)->select('name')->first();



        return view('admin.case.zgck',['case'=>$case,'headline'=>$headline,'unit'=>$unit,'user'=>$user,'peo'=>$peo,'peos'=>$peos]);
    }

      //企业整改通知书查看
    public function qzgck($id,Request $request){
        $case = DB::table('cases')->where('case_id',$id)->first();
        $headline = DB::table('casedeadline')->where('case_id',$id)->first();
      
        return view('admin.case.qzgck',['case'=>$case,'headline'=>$headline]);
    }





    //限期整改通知书上传改变状态
       public function xquploads(){

                     $data['img'] = $_POST['img'];
                     $re =  DB::table('ceshi')->insert($data);
                     $base64 = $_POST['img'];
                     exit();


                    $map['is_deadline'] = '1';
                    $map['is_deadlineok'] = '0';
                    DB::table('cases')->where('case_id',$_POST['caseid'])->update($map);

                //获取扩告知通知书展名
                // $cont =  $file->getClientOriginalName();
                // $tmpName = $file ->getFileName();
                // $extension = $file -> getClientOriginalExtension();
                // $filedir="storage/uploads/"; //2、定义图片上传路径
                // $newImagesName=md5(time()).random_int(5,5).".".$extension;
                // $file->move($filedir,$newImagesName);

                     $url = explode(',', $base64);
                    
                     $paths = "./storage/uploads/";
                     $prefix='hj_';
                     $output_file = $prefix.time().rand(100,999).'.jpg';
                     $path = $paths.$output_file;
                     $a = file_put_contents($path, base64_decode($url[1]));//返回的是字节数

                     $ch['one_pic'] = $output_file;
                     $re =  DB::table('casedeadline')->where('case_id',$_POST['caseid'])->update($ch);

                     if ($re) {
                        $result = array('message' =>'上传成功','style'=>1);
                        echo json_encode($result,TRUE);
                        exit();
                    
                     }

                    
                  
      }






    //整改延期
    public function upno($id,Request $request)
    {
        //




        $case = DB::table('cases')->where('case_id',$id)->first();

        //获取期限
        $hl = array(
          'case_id' => $id,
        );
        $headline = DB::table('casedeadline')->where($hl)->first();


        //获取延期的日期
        if ($case->is_delay === 1) {
          $hh = array(
            'case_id' => $id,
            'is_type' => 1,
          );
          $hdl = DB::table('casedeadline')->where($hh)->first();
        }




        if($request->isMethod('post')){
          //是否存在参数
          $input = $request->all();
            if($input['start']){
              $data = Input::except('_token');

              $data = array(
                  'yan_start' => $input['start'],
                  'yan_end' => $input['end'],
                  'update_uid' => Auth::guard('admin')->user()->id,
                  'yan_created_at' =>$this->time(),
                  'is_type' => 1,
              );
              DB::table('casedeadline')->where('case_id',$id)->update($data);

              $delay = array(
                'is_delay' => 1,
                'is_delayok'=> 0,
              );
              DB::table('cases')->where('case_id',$id)->update($delay);
              //跳入整改延期
              return redirect("admin/case/index");
              }else{
                echo "<script>alert('请填写开始日期!');window.history.go(-1);</script>";
              }
        }

        //获取延期的日期
        if ($case->is_delay === 1) {

            return view('admin.case.upno',['case'=>$case,'headline'=>$headline,'hdl'=>$hdl]);
            
        }else{

            return view('admin.case.upno',['case'=>$case,'headline'=>$headline]);
        }


    }





    /**
     * Update the specified resource in storage.s
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }




    //案件类型
    public function type(){

      $type = DB::table('casetype')->orderBy('id','desc')->get();
      $count = DB::table('casetype')->count();
      return view('admin.case.type',['type'=>$type,'count'=>$count]);
    }

    //添加案件类型
    public function typeadd(Request $request ){
      //表单提交
      if($request->isMethod('post')){
        //是否存在参数
        $input = $request->all();
          if($input['name']){
              $data = Input::except('_token');
              $data['name'] = $input['name'];
              $data['created_at'] = $this->time();

              DB::table('casetype')->insert($data);
              return redirect('admin/case/type');
          }else{
            echo "<script>alert('类型名称不能为空!');window.history.go(-1);</script>";
          }
      }
        return view('admin.case.typeadd');
    }

    //修改案件类型
      public function edit_type($id,Request $request){

        $type = DB::table('casetype')->where('id',$id)->first();



        if($request->isMethod('post')){
          //是否存在参数
          $input = $request->all();
            if($input['name']){
                $data = Input::except('_token');
                $data['name'] = $input['name'];
                $data['updated_at'] = $this->time();
                DB::table('casetype')->where('id',$id)->update($data);
                return redirect('admin/case/type');
            }else{
              echo "<script>alert('类型名称不能为空!');window.history.go(-1);</script>";
            }
        }
          return view('admin.case.edit_type',['type'=>$type]);

      }
      //删除类型
      public function deltype($id)
      {
          $re = db::table('casetype')->where('id',$id)->first();
          if ($re) {
              DB::table('casetype')->where('id',$id)->delete();
              return redirect()->back();
          } else {
              echo "<script>alert('删除失败!');window.history.go(-1);</script>";
          }
      }


      //删除案件
      public function del($id)
      {
        $re = db::table('cases')->where('case_id',$id)->first();
        if ($re) {
            DB::table('cases')->where('case_id',$id)->delete();
            return redirect()->back();
        } else {
            echo "<script>alert('删除失败!');window.history.go(-1);</script>";
        }
      }


      //通过整改时间审核
      public function dt($id,Request $request)
      {
            $re = DB::table('cases')->where('case_id',$id)->first();
            $data = array(
              'is_deadlineok' => 1
             );
             $re =  DB::table('cases')->where('case_id',$id)->update($data);
             if ($re) {
                return redirect()->back();
             }

      }

      //通过整改时间拒绝
      public function dj($id,Request $request)
      {
          $re = DB::table('cases')->where('case_id',$id)->first();
          $data = array(
              'is_deadlineok' => 2,
              'is_deadline' => 0,
          );
          $re =  DB::table('cases')->where('case_id',$id)->update($data);
          if ($re) {
             DB::table('casedeadline')->where('case_id',$id)->delete();
             return redirect()->back();
          }
      }


      //通过整改时间审批
      public function lddt($id,Request $request)
      {   



            $re = DB::table('cases')->where('case_id',$id)->first();

            $un  = DB::table('casedeadline')->where('case_id',$id)->first();

          //添加印章
                        //图1主图
                        $path_1 = "./storage/uploads/" . $un->one_pic;
                      
                        //图2
                       
                        $path_2 = "./"."yz.jpg";
                        //将l两张图片分别取到两个画布中
                        $path_1_type = getimagesize($path_1);
                        $path_2_type = getimagesize($path_2);
                        if ($path_1_type['mime'] == 'image/png') {
                            $image_1 = imagecreatefrompng($path_1);
                        }
                        if ($path_1_type['mime'] == 'image/jpeg') {
                            $image_1 = imagecreatefromjpeg($path_1);
                        }
                        if ($path_2_type['mime'] == 'image/png') {
                            $image_2 = imagecreatefrompng($path_2);

                        }
                        if ($path_2_type['mime'] == 'image/jpeg') {
                            $image_2 = imagecreatefromjpeg($path_2);
                        }
                        //创建一个和图1一样大小的真彩色画布
                        $image_3 = imageCreatetruecolor(imagesx($image_1), imagesy($image_1));
                        //为真彩色画布创建白色背景，再设置为透明
                        $color = imagecolorallocate($image_3, 255, 255, 255);
                        imagefill($image_3, 0, 0, $color);
                        imageColorTransparent($image_3, $color);
                        //首先将图1放到画布中
                        imagecopyresampled($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), imagesx($image_1), imagesy($image_1));
                        //再将图2放到画布中
                        $x = imagesx($image_3) - 260;
                        $y = imagesy($image_3) - 480;
                        imagecopymerge($image_3, $image_2, $x, $y, 0, 0, imagesx($image_2), imagesy($image_2), 50);
                        //将画布保存到指定的文件
                        $ymd = date('Y-m-d', time());
                        $rootPath = './storage/uploads/';
                        $savePath = $ymd.$id.'.jpeg';
                        $success = imagejpeg($image_3, $rootPath . $savePath);

                        if ($success) {

                           //如果盖章成功，将结果保存到数据库
                             $un = array(
                               'one_pic' => $savePath,
                               'last_uid' => Auth::guard('admin')->user()->id,
                              );
                             DB::table('casedeadline')->where('case_id',$id)->update($un);


                            $log = array(
                              'case_id' => $id,
                              'uid' => Auth::guard('admin')->user()->id,
                              'type'=>1,

                              );
                             DB::table('yzlog')->insert($log);


          

                             $data = array(
                              'is_deadlineok' => 3
                             );
                             $re =  DB::table('cases')->where('case_id',$id)->update($data);
                             if ($re) {
                                return redirect()->back();
                             }


                        } 



          

      }

      //通过整改时间拒绝审批
      public function lddj($id,Request $request)
      {
          $re = DB::table('cases')->where('case_id',$id)->first();
          $data = array(
              'is_deadlineok' => 2,
              'is_deadline' => 0,
          );
          $re =  DB::table('cases')->where('case_id',$id)->update($data);
          if ($re) {
             DB::table('casedeadline')->where('case_id',$id)->delete();
             return redirect()->back();
          }
      }




      //通过延期时间审核
      public function delaydt($id,Request $request)
      {


       $case = DB::table('cases')->where('case_id',$id)->first();

       $headline = DB::table('casedeadline')->where('case_id',$id)->first();

       //获取单位
       $un = array(
          'id' => $case->case_address,
        );
       $unit = DB::table('units')->where($un)->select('name')->first();


          //获取组织
       $uid = array(
         'admin_users.id' => $headline->update_uid,
       );
      $user = DB::table('admin_users')->where($uid)->join('org', 'admin_users.org_id', '=', 'org.id')->select('admin_users.org_id', 'admin_users.id','org.name')->first();
        return view('admin.case.delaydt',['case'=>$case,'headline'=>$headline,'unit'=>$unit,'user'=>$user]);
      }

      //延期审核通过理由填写
      public function delaydtone($id,Request $request){
         $case = DB::table('cases')->where('case_id',$id)->first();

        if($request->isMethod('post')){
          //是否存在参数
          $input = $request->all();

            if($input['case_desc']){
                $data = Input::except('_token');

                $data = array(
                    'yan_liyou' => $input['case_desc'],
                );
                DB::table('casedeadline')->where('case_id',$id)->update($data);
                return redirect("admin/case/delaydt/$id");
            }else{
              echo "<script>alert('理由不能为空!');window.history.go(-1);</script>";
            }
        }



        return view('admin.case.delaydtone',['case'=>$case]);
      }


       //限期整改通知书上传改变状态
       public function uptyxq(){


             $data['img'] = $_POST['img'];
             $re =  DB::table('ceshi')->insert($data);
             $base64 = $_POST['img'];


              $datas = array(
                'is_delayok' => 1,
               );
              DB::table('cases')->where('case_id',$_POST['caseid'])->update($datas);
          

            // $map['is_deadline'] = '1';
            // $map['is_deadlineok'] = '0';
            // DB::table('cases')->where('case_id',$_POST['caseid'])->update($map);

     
             $url = explode(',', $base64);
             $paths = "./storage/uploads/";
             $prefix='hj_';
             $output_file = $prefix.time().rand(100,999).'.jpg';
             $path = $paths.$output_file;
             $a = file_put_contents($path, base64_decode($url[1]));//返回的是字节数

             $ch['yan_pic'] = $output_file;
             $re =  DB::table('casedeadline')->where('case_id',$_POST['caseid'])->update($ch);

             if ($re) {
                $result = array('message' =>'上传成功','style'=>1);
                echo json_encode($result,TRUE);
                exit();
            
             }

                    
                  
      }

      //延期时间拒绝
      public function delaydj($id,Request $request)
      {
          $re = DB::table('cases')->where('case_id',$id)->first();
          $data = array(
              'is_delayok' => 2,
              'is_delay' => 0,
          );
          $re =  DB::table('cases')->where('case_id',$id)->update($data);
          if ($re) {

            // $ma = array(

            //   'update_uid' => '',
            //   'is_type' => '0',
            //   'yan_start' => '',
            //   'yan_created_at' => '',
            // );

          
            //  DB::table('casedeadline')->where('case_id',$id)->update($ma);
              return redirect("admin/case/index");
          }
      }


      //领导通过延期时间审批
      public function delaylddt($id,Request $request)
      {
          $re = DB::table('cases')->where('case_id',$id)->first();

          $un  = DB::table('casedeadline')->where('case_id',$id)->first();

          //添加印章
          //图1主图
          $path_1 = "./storage/uploads/" . $un->yan_pic;

          //图2
          $path_2 = "./"."yz.jpg";
          //将l两张图片分别取到两个画布中
          $path_1_type = getimagesize($path_1);
          $path_2_type = getimagesize($path_2);
          if ($path_1_type['mime'] == 'image/png') {
              $image_1 = imagecreatefrompng($path_1);
          }
          if ($path_1_type['mime'] == 'image/jpeg') {
              $image_1 = imagecreatefromjpeg($path_1);
          }
          if ($path_2_type['mime'] == 'image/png') {
              $image_2 = imagecreatefrompng($path_2);

          }
          if ($path_2_type['mime'] == 'image/jpeg') {
              $image_2 = imagecreatefromjpeg($path_2);
          }
          //创建一个和图1一样大小的真彩色画布
          $image_3 = imageCreatetruecolor(imagesx($image_1), imagesy($image_1));
          //为真彩色画布创建白色背景，再设置为透明
          $color = imagecolorallocate($image_3, 255, 255, 255);
          imagefill($image_3, 0, 0, $color);
          imageColorTransparent($image_3, $color);
          //首先将图1放到画布中
          imagecopyresampled($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), imagesx($image_1), imagesy($image_1));
          //再将图2放到画布中
          $x = imagesx($image_3) - 500;
          $y = imagesy($image_3) - 480;
          imagecopymerge($image_3, $image_2, $x, $y, 0, 0, imagesx($image_2), imagesy($image_2), 50);
          //将画布保存到指定的文件
          $ymd = date('Y-m-d', time());
          $rootPath = './storage/uploads/';
          $yq = 'yqt';
          $savePath = $ymd.$id.$yq.'.jpeg';
          $success = imagejpeg($image_3, $rootPath . $savePath);

          if ($success) {

             $data = array(
                'is_delayok' => 3
               );
             $re =  DB::table('cases')->where('case_id',$id)->update($data);
             if ($re) {

                $un = array(
                   'yan_pic' => $savePath,
                   'last_uid' => Auth::guard('admin')->user()->id,
                  );
                 DB::table('casedeadline')->where('case_id',$id)->update($un);


                $log = array(
                  'case_id' => $id,
                  'uid' => Auth::guard('admin')->user()->id,
                  'type'=>4,

                  );
                 DB::table('yzlog')->insert($log);


                return redirect("admin/case/index");


                 // $ma = array(
                 //   'case_id' =>$id,
                 //   'is_type' => 0,
                 // );
                 // DB::table('casedeadline')->where($ma)->delete();

                 // $mas = array(
                 //   'case_id' => $id,
                 //   'is_type'=> 1,
                 // );

                 // $upmas = array(
                 //    'is_type' => 0,
                 // );
                 // DB::table('casedeadline')->where($mas)->update($upmas);
                
             }

          }





            

      }

      //延期时间拒绝
      public function delaylddj($id,Request $request)
      {
          $re = DB::table('cases')->where('case_id',$id)->first();
          $data = array(
              'is_delayok' => 2,
              'is_delay' => 0,
          );
          $re =  DB::table('cases')->where('case_id',$id)->update($data);
          if ($re) {
            $ma = array(
              
              'is_type' => 0,
            );

             DB::table('casedeadline')->where('case_id',$id)->update($ma);
              return redirect("admin/case/index");
          }
      }





      //复查案件列表
      public function fucha(){
        //

          $map = array(
              'is_deadline'=> 1,
              'is_deadlineok' =>3,
          );

          $re = DB::table('cases')->where($map)->orderBy('case_id','desc')->paginate(10);
          $count = DB::table('cases')->where($map)->count();
          return view('admin.case.fucha',['re'=>$re,'count'=>$count]);
      }

      //复查案件详情
      public function fcedit($id,Request $request){
        //获取分类和案件
        $case = DB::table('cases')->where('case_id',$id)->first();
        $type = DB::table('casetype')->orderBy('id','desc')->get();
        //获取单位列表
        $units = DB::table('units')->orderBy('id','desc')->get();


        if ($case->case_hege == 2) {
            $un = DB::table('casehge')->where('case_id',$id)->join('admin_users', 'casehge.send_uid', '=', 'admin_users.id')->select('casehge.*', 'admin_users.name')->first();

        }

         if ($case->case_hege == 1) {
            $un = DB::table('casehge')->where('case_id',$id)->join('admin_users', 'casehge.send_uid', '=', 'admin_users.id')->select('casehge.*', 'admin_users.name')->first();

        }

        //获取限期整改
        $hd = array(
          'case_id' => $id,
          
        );
        $cd = DB::table('casedeadline')->where($hd)->join('admin_users', 'casedeadline.uid', '=', 'admin_users.id')->select('casedeadline.*', 'admin_users.name')->first();


        if ($case->case_hege == 2 || $case->case_hege == 1) {
          return view('admin.case.fcedit',['type'=>$type,'case'=>$case,'units'=>$units,'cd'=>$cd,'un'=>$un]);
        }else{
          return view('admin.case.fcedit',['type'=>$type,'case'=>$case,'units'=>$units,'cd'=>$cd]);
        }

      }


      //申请复查
      public function fcsq($id,Request $request){

        $re = DB::table('cases')->where('case_id',$id)->first();
        $data = array(
            'is_review' => 1,
            'is_reviewok' => 0,
        );
        $re =  DB::table('cases')->where('case_id',$id)->update($data);
        if ($re) {
            return redirect("admin/case/fucha");
        }
      }



            //通过复查审批
            public function fctg($id,Request $request)
            {
                  $re = DB::table('cases')->where('case_id',$id)->first();
                  $data = array(
                    'is_reviewok' => 1
                   );
                   $re =  DB::table('cases')->where('case_id',$id)->update($data);
                   if ($re) {
                       return redirect("admin/case/fucha");
                   }

            }

            //复查审批拒绝
            public function fcjt($id,Request $request)
            {
                $re = DB::table('cases')->where('case_id',$id)->first();
                $data = array(
                    'is_reviewok' => 2,
                    'is_review' => 0,
                );
                $re =  DB::table('cases')->where('case_id',$id)->update($data);
                if ($re) {
                    return redirect("admin/case/fucha");
                }
            }


            //整改合格
            public function zghg($id,Request $request)
            {

              //存入数据库casehge


              $re = DB::table('cases')->where('case_id',$id)->first();
              $hg = DB::table('casehge')->where('case_id',$id)->first();


              if($request->isMethod('post')){
                //是否存在参数
                $input = $request->all();
                  if($input['un_cont']){
                      $data = Input::except('_token');

                      // $data = array(
                      //     'un_cont' => $input['un_cont'],
                      //     'uid'=>Auth::guard('admin')->user()->id,
                      //     'case_id' => $id,
                      // );
                      // DB::table('case_unqualified')->insert($data);
                      if($hg)
                      {
                        $data = array(
                            'check_time' => $input['start'],
                            'cont' => $input['un_cont'],
                            'send_uid'=>Auth::guard('admin')->user()->id,
                            'type' => 1,
                            'guiding' => 1,
                        );

                        DB::table('casehge')->where('case_id',$id)->update($data);


                      }else{
                        $data = array(
                            'check_time' => $input['start'],
                            'cont' => $input['un_cont'],
                            'send_uid'=>Auth::guard('admin')->user()->id,
                            'case_id' => $id,
                            'type' => 1,
                            'guiding' => 1,
                        );

                        DB::table('casehge')->insert($data);
                      }


                      // $ca = array(
                      //   'case_hege' => 2,
                      //   'case_hegeok'=>0,
                      // );

                      // DB::table('cases')->where('case_id',$id)->update($ca);
                      //跳入告知书
                      // return redirect('admin/case/fucha');
                      
                   return redirect("admin/case/bhgck/$id");


                  }else{
                    echo "<script>alert('不合格理由不能为空!');window.history.go(-1);</script>";
                  }
              }




              return view('admin.case.zghg',['re'=>$re]);


            }



            //整改不合格
            public function zgbhg($id,Request $request)
            {


              //存入数据库casehge


              $re = DB::table('cases')->where('case_id',$id)->first();
              $hg = DB::table('casehge')->where('case_id',$id)->first();


              if($request->isMethod('post')){
                //是否存在参数
                $input = $request->all();
                  if($input['un_cont']){
                      $data = Input::except('_token');

                      // $data = array(
                      //     'un_cont' => $input['un_cont'],
                      //     'uid'=>Auth::guard('admin')->user()->id,
                      //     'case_id' => $id,
                      // );
                      // DB::table('case_unqualified')->insert($data);
                      if($hg)
                      {
                        $data = array(
                            'check_time' => $input['start'],
                            'cont' => $input['un_cont'],
                            'send_uid'=>Auth::guard('admin')->user()->id,
                            'type' => 2,
                            'guiding' => 2,
                        );

                        DB::table('casehge')->where('case_id',$id)->update($data);


                      }else{
                        $data = array(
                            'check_time' => $input['start'],
                            'cont' => $input['un_cont'],
                            'send_uid'=>Auth::guard('admin')->user()->id,
                            'case_id' => $id,
                            'type' => 2,
                            'guiding' => 2,
                        );

                        DB::table('casehge')->insert($data);
                      }


                      // $ca = array(
                      //   'case_hege' => 2,
                      //   'case_hegeok'=>0,
                      // );

                      // DB::table('cases')->where('case_id',$id)->update($ca);
                      //跳入告知书
                      // return redirect('admin/case/fucha');
                      
                   return redirect("admin/case/bhgck/$id");


                  }else{
                    echo "<script>alert('不合格理由不能为空!');window.history.go(-1);</script>";
                  }
              }




              return view('admin.case.zgbhg',['re'=>$re]);

            }


            //复查意见告知书
            public function bhgck($id,Request $request)
            { 

               $case = DB::table('cases')->where('case_id',$id)->first();

               $hg = DB::table('casehge')->where('case_id',$id)->first();

               //获取单位
               $un = array(
                  'id' => $case->case_address,
                );
               $unit = DB::table('units')->where($un)->select('name')->first();

               //获取组织
               $uid = array(
                 'admin_users.id' => $hg->send_uid,
               );
              $user = DB::table('admin_users')->where($uid)->join('org', 'admin_users.org_id', '=', 'org.id')->select('admin_users.org_id', 'admin_users.id','org.name')->first();
        

              return view('admin.case.bhgck',['case'=>$case,'hg'=>$hg,'unit'=>$unit,'user'=>$user]);
            }

            //上传复查意见告知书
            public function upbhg(){

                    $data['img'] = $_POST['img'];
                    $re =  DB::table('ceshi')->insert($data);
                    $base64 = $_POST['img'];


                     $ca = array(
                        'case_hege' => 2,
                        'case_hegeok'=>0,
                      );

                     DB::table('cases')->where('case_id',$_POST['caseid'])->update($ca);

                //获取扩告知通知书展名
                // $cont =  $file->getClientOriginalName();
                // $tmpName = $file ->getFileName();
                // $extension = $file -> getClientOriginalExtension();
                // $filedir="storage/uploads/"; //2、定义图片上传路径
                // $newImagesName=md5(time()).random_int(5,5).".".$extension;
                // $file->move($filedir,$newImagesName);

                     $url = explode(',', $base64);
                    
                     $paths = "./storage/uploads/";
                     $prefix='hj_';
                     $output_file = $prefix.time().rand(100,999).'.jpg';
                     $path = $paths.$output_file;
                     $a = file_put_contents($path, base64_decode($url[1]));//返回的是字节数

                     $ch['pic'] = $output_file;
                     $re =  DB::table('casehge')->where('case_id',$_POST['caseid'])->update($ch);

                     if ($re) {
                        $result = array('message' =>'上传成功','style'=>1);
                        echo json_encode($result,TRUE);
                        exit();
                    
                     }




            }









            //合格领导复查最终审批通过
            public function ldzghg($id,Request $request){



                    $re = DB::table('cases')->where('case_id',$id)->first();

                    $un  = DB::table('casehge')->where('case_id',$id)->first();

                    //添加印章
                        //图1主图
                        $path_1 = "./storage/uploads/" . $un->pic;
                      
                        //图2
                       
                        $path_2 = "./"."yz.jpg";
                        //将l两张图片分别取到两个画布中
                        $path_1_type = getimagesize($path_1);
                        $path_2_type = getimagesize($path_2);
                        if ($path_1_type['mime'] == 'image/png') {
                            $image_1 = imagecreatefrompng($path_1);
                        }
                        if ($path_1_type['mime'] == 'image/jpeg') {
                            $image_1 = imagecreatefromjpeg($path_1);
                        }
                        if ($path_2_type['mime'] == 'image/png') {
                            $image_2 = imagecreatefrompng($path_2);

                        }
                        if ($path_2_type['mime'] == 'image/jpeg') {
                            $image_2 = imagecreatefromjpeg($path_2);
                        }
                        //创建一个和图1一样大小的真彩色画布
                        $image_3 = imageCreatetruecolor(imagesx($image_1), imagesy($image_1));
                        //为真彩色画布创建白色背景，再设置为透明
                        $color = imagecolorallocate($image_3, 255, 255, 255);
                        imagefill($image_3, 0, 0, $color);
                        imageColorTransparent($image_3, $color);
                        //首先将图1放到画布中
                        imagecopyresampled($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), imagesx($image_1), imagesy($image_1));
                        //再将图2放到画布中
                        $x = imagesx($image_3) - 260;
                        $y = imagesy($image_3) - 480;
                        imagecopymerge($image_3, $image_2, $x, $y, 0, 0, imagesx($image_2), imagesy($image_2), 50);
                        //将画布保存到指定的文件
                        $ymd = date('Y-m-d', time());
                        $rootPath = './storage/uploads/';
                        $s = 'hgtt';
                        $savePath = $ymd.$id.$s.'.jpeg';
                        $success = imagejpeg($image_3, $rootPath . $savePath);

                        if ($success) {

                           //如果盖章成功，将结果保存到数据库
                             $un = array(
                               'pic' => $savePath,
                               'last_uid' => Auth::guard('admin')->user()->id,
                              );
                             DB::table('casehge')->where('case_id',$id)->update($un);


                            $log = array(
                              'case_id' => $id,
                              'uid' => Auth::guard('admin')->user()->id,
                              'type'=>5,

                              );
                             DB::table('yzlog')->insert($log);
          
                              $data = array(
                                'case_hegeok' => 1,
                                'is_closed'=>1,
                              );
                              $re =  DB::table('cases')->where('case_id',$id)->update($data);
                              if ($re) {
                                  return redirect("admin/case/index");
                              }


                        } 


             
            }







            //合格领导复查最终审批拒拒绝通过
            public function ldzgbhg($id,Request $request){
              $data = array(
                  'case_hegeok' => 2,
                  'case_hege'=>0,
              );
              $re =  DB::table('cases')->where('case_id',$id)->update($data);
              if ($re) {
                  return redirect("admin/case/fucha");
              }
            }




           //不合格合格领导复查最终审批通过
           public function bldzghg($id, Request $request){

                    $re = DB::table('cases')->where('case_id',$id)->first();

                    $un  = DB::table('casehge')->where('case_id',$id)->first();

                    //添加印章
                        //图1主图
                        $path_1 = "./storage/uploads/" . $un->pic;
                      
                        //图2
                       
                        $path_2 = "./"."yz.jpg";
                        //将l两张图片分别取到两个画布中
                        $path_1_type = getimagesize($path_1);
                        $path_2_type = getimagesize($path_2);
                        if ($path_1_type['mime'] == 'image/png') {
                            $image_1 = imagecreatefrompng($path_1);
                        }
                        if ($path_1_type['mime'] == 'image/jpeg') {
                            $image_1 = imagecreatefromjpeg($path_1);
                        }
                        if ($path_2_type['mime'] == 'image/png') {
                            $image_2 = imagecreatefrompng($path_2);

                        }
                        if ($path_2_type['mime'] == 'image/jpeg') {
                            $image_2 = imagecreatefromjpeg($path_2);
                        }
                        //创建一个和图1一样大小的真彩色画布
                        $image_3 = imageCreatetruecolor(imagesx($image_1), imagesy($image_1));
                        //为真彩色画布创建白色背景，再设置为透明
                        $color = imagecolorallocate($image_3, 255, 255, 255);
                        imagefill($image_3, 0, 0, $color);
                        imageColorTransparent($image_3, $color);
                        //首先将图1放到画布中
                        imagecopyresampled($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), imagesx($image_1), imagesy($image_1));
                        //再将图2放到画布中
                        $x = imagesx($image_3) - 260;
                        $y = imagesy($image_3) - 480;
                        imagecopymerge($image_3, $image_2, $x, $y, 0, 0, imagesx($image_2), imagesy($image_2), 50);
                        //将画布保存到指定的文件
                        $ymd = date('Y-m-d', time());
                        $rootPath = './storage/uploads/';
                        $savePath = $ymd.$id.'.jpeg';
                        $success = imagejpeg($image_3, $rootPath . $savePath);

                        if ($success) {

                           //如果盖章成功，将结果保存到数据库
                             $un = array(
                               'pic' => $savePath,
                               'last_uid' => Auth::guard('admin')->user()->id,
                              );
                             DB::table('casehge')->where('case_id',$id)->update($un);


                            $log = array(
                              'case_id' => $id,
                              'uid' => Auth::guard('admin')->user()->id,
                              'type'=>2,

                              );
                             DB::table('yzlog')->insert($log);
        
                             $data = array(
                                 'case_hegeok' => 1,
                             );
                             $re =  DB::table('cases')->where('case_id',$id)->update($data);
                             if ($re) {
                                 return redirect("admin/case/index");
                             }


                        } 



          
           }


            //不合格领导复查最终审批拒拒绝通过
            public function bldzgbhg($id,Request $Request){
              $data = array(
                'case_hegeok' => 2,
                'case_hege'=>0,
              );
              $re = DB::table('cases')->where('case_id',$id)->update($data);
              if ($re) {
                //删除
                return redirect('admin/case/fucha');
              }
            }


            //提交不合格相关资料
            public function tjbhg($id,Request $request){

              $re = DB::table('cases')->where('case_id',$id)->first();
              $hg = DB::table('case_chufa')->where('case_id',$id)->first();



              if($request->isMethod('post')){
                //是否存在参数
                $input = $request->all();
                  if($input['cont']){
                      $data = Input::except('_token');

                      // $data = array(
                      //     'un_cont' => $input['un_cont'],
                      //     'uid'=>Auth::guard('admin')->user()->id,
                      //     'case_id' => $id,
                      // );
                      // DB::table('case_unqualified')->insert($data);
                      if($hg)
                      {
                        $data = array(
                            
                            'cont' => $input['cont'],
                            'zjss' => $input['zjss'],
                            'cffs' => $input['cffs'],
                            'zxfs' => $input['zxfs'],
                            'sqga' => $input['sqga'],
                            'ssfy' => $input['ssfy'],
                            'cfd' => $input['cfd'],
                            'bamj' => $input['bamj'],
                         

                            'send_uid'=>Auth::guard('admin')->user()->id,
                           
                        );

                        DB::table(' case_chufa')->where('case_id',$id)->update($data);


                      }else{
                        $data = array(
                            'cont' => $input['cont'],
                            'zjss' => $input['zjss'],
                            'cffs' => $input['cffs'],
                            'zxfs' => $input['zxfs'],
                            'sqga' => $input['sqga'],
                            'ssfy' => $input['ssfy'],
                            'cfd' => $input['cfd'],
                            'bamj' => $input['bamj'],

                            'send_uid'=>Auth::guard('admin')->user()->id,
                            'case_id' => $id,
                           
                        );

                        DB::table('case_chufa')->insert($data);
                      }


                      // $ca = array(
                      //   'case_hege' => 2,
                      //   'case_hegeok'=>0,
                      // );

                      // DB::table('cases')->where('case_id',$id)->update($ca);
                      //跳入告知书
                      // return redirect('admin/case/fucha');
                      
                   return redirect("admin/case/cfck/$id");


                  
                  }else{
                    echo "<script>alert('查明不能为空!');window.history.go(-1);</script>";
                  }
              }

              return view('admin.case.tjbhg',['re'=>$re]);

              // if($file && $files){

              //    //获取扩告知通知书展名
              //   $cont =  $file->getClientOriginalName();
              //   $tmpName = $file ->getFileName();
              //   $extension = $file -> getClientOriginalExtension();
              //   $filedir="storage/uploads/"; //2、定义图片上传路径
              //   $newImagesName=md5(time()).random_int(5,5).".".$extension;
              //   $file->move($filedir,$newImagesName);


              //   //获取法律文书
              //   $extension2 = $files -> getClientOriginalExtension();
              //   $newImagesName2=md5(time()).random_int(5,5).".".$extension2;
              //   $files->move($filedir,$newImagesName2);


              //   //存入数据里



              //   $arr = array(
              //       'un_gaozhi' => $newImagesName,
              //       'un_fv'=>$newImagesName2,
              //   );

              //   $res = DB::table('case_unqualified')->where('case_id',$id)->update($arr);

      

              //     if ($res) {
              //         return redirect('admin/case/fucha');
              //     }

              //   }else{
              //         
              // 
            }
            //查看处罚单
            public function cfck($id,Request $request){
                $case = DB::table('cases')->where('case_id',$id)->first();

               $hg = DB::table('case_chufa')->where('case_id',$id)->first();

               //获取单位
               $un = array(
                  'id' => $case->case_address,
                );
               $unit = DB::table('units')->where($un)->first();

              //  //获取组织
              //  $uid = array(
              //    'admin_users.id' => $hg->send_uid,
              //  );
              // $user = DB::table('admin_users')->where($uid)->join('org', 'admin_users.org_id', '=', 'org.id')->select('admin_users.org_id', 'admin_users.id','org.name')->first();

              return view('admin.case.cfck',['case'=>$case,'hg'=>$hg,'unit'=>$unit]);

            }


            //上传处罚图片

             public function upcf(){

                $data['img'] = $_POST['img'];
                $re =  DB::table('ceshi')->insert($data);
              
                $base64 = $_POST['img'];


                 //改变
                $c = array(
                    'is_punish' => 1,
                  );
                DB::table('cases')->where('case_id',$_POST['caseid'])->update($c);
                //获取扩告知通知书展名
                // $cont =  $file->getClientOriginalName();
                // $tmpName = $file ->getFileName();
                // $extension = $file -> getClientOriginalExtension();
                // $filedir="storage/uploads/"; //2、定义图片上传路径
                // $newImagesName=md5(time()).random_int(5,5).".".$extension;
                // $file->move($filedir,$newImagesName);

                   $url = explode(',', $base64);
                  
                   $paths = "./storage/uploads/";
                   $prefix='hj_';
                   $output_file = $prefix.time().rand(100,999).'.jpg';
                   $path = $paths.$output_file;
                   $a = file_put_contents($path, base64_decode($url[1]));//返回的是字节数

                   $ch['pic'] = $output_file;
                   $re =  DB::table('case_chufa')->where('case_id',$_POST['caseid'])->update($ch);

                   if ($re) {
                      $result = array('message' =>'上传成功','style'=>1);
                      echo json_encode($result,TRUE);
                      exit();
                  
                   }

            }







            //不合格领导复查最终审批拒拒绝文件
            public function wjj($id,Request $Request){
              $data = array(
                'is_punish'=>0,
              );
              $re = DB::table('cases')->where('case_id',$id)->update($data);
              if ($re) {
                //删除

                $arr = array(
                  'un_gaozhi'=>'',
                  'un_fv'=>'',
                );
                DB::table('case_unqualified')->where('case_id',$id)->update($arr);


                return redirect('admin/case/fucha');
              }
            }



            //不合格领导复查最终审批通过文件
            public function wjt($id,Request $Request){


                    $re = DB::table('cases')->where('case_id',$id)->first();

                    $un  = DB::table('case_chufa')->where('case_id',$id)->first();



                    //添加印章
                        //图1主图
                        $path_1 = "./storage/uploads/" . $un->pic;
                      
                        //图2
                       
                        $path_2 = "./"."yz.jpg";
                        //将l两张图片分别取到两个画布中
                        $path_1_type = getimagesize($path_1);
                        $path_2_type = getimagesize($path_2);
                        if ($path_1_type['mime'] == 'image/png') {
                            $image_1 = imagecreatefrompng($path_1);
                        }
                        if ($path_1_type['mime'] == 'image/jpeg') {
                            $image_1 = imagecreatefromjpeg($path_1);
                        }
                        if ($path_2_type['mime'] == 'image/png') {
                            $image_2 = imagecreatefrompng($path_2);

                        }
                        if ($path_2_type['mime'] == 'image/jpeg') {
                            $image_2 = imagecreatefromjpeg($path_2);
                        }
                        //创建一个和图1一样大小的真彩色画布
                        $image_3 = imageCreatetruecolor(imagesx($image_1), imagesy($image_1));
                        //为真彩色画布创建白色背景，再设置为透明
                        $color = imagecolorallocate($image_3, 255, 255, 255);
                        imagefill($image_3, 0, 0, $color);
                        imageColorTransparent($image_3, $color);
                        //首先将图1放到画布中
                        imagecopyresampled($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), imagesx($image_1), imagesy($image_1));
                        //再将图2放到画布中
                        $x = imagesx($image_3) - 260;
                        $y = imagesy($image_3) - 480;
                        imagecopymerge($image_3, $image_2, $x, $y, 0, 0, imagesx($image_2), imagesy($image_2), 50);
                        //将画布保存到指定的文件
                        $ymd = date('Y-m-d', time());
                        $type = 'cf';
                        $rootPath = './storage/uploads/';
                        $savePath = $ymd.$id.$type.'.jpeg';
                        $success = imagejpeg($image_3, $rootPath . $savePath);




                        if ($success) {


                           //如果盖章成功，将结果保存到数据库
                             $un = array(
                               'pic' => $savePath,
                               'laset_uid' => Auth::guard('admin')->user()->id,
                              );
                             DB::table('case_chufa')->where('case_id',$id)->update($un);


                            $log = array(
                              'case_id' => $id,
                              'uid' => Auth::guard('admin')->user()->id,
                              'type'=>3,

                              );
                             DB::table('yzlog')->insert($log);
        
                            $data = array(
                              'is_closed'=>1,
                            );

                            $re = DB::table('cases')->where('case_id',$id)->update($data);
                            if ($re) {
                              return redirect('admin/case/index');
                            }


                        } 




            }






            //综合案件查询
            public function zhcase(request $request){

                //获取分类
                $type = DB::table('casetype')->orderBy('id','desc')->get();

                //获取单位列表
                $units = DB::table('units')->orderBy('id','desc')->get();



                 if($request->isMethod('post')){

                      if (input::get('name') == '' && input::get('case_address')=='' && input::get('is_closed') == 3 && input::get('case_hege')=='' && input::get('is_punish') == 3 && input::get('is_delay') == 3) {
                          echo "<script>alert('至少选择一个筛选条件!');window.history.go(-1);</script>";
                      }
                      

                      if(input::get('name')){
                        $map[] = array('case_name','like','%'.input::get('name').'%');
                      }

                      if(input::get('case_address')){
                        $map['case_address'] = input::get('case_address');
                       
                      }
                      if(input::get('is_closed') != 3){
                        $map['is_closed'] = input::get('is_closed');
                       
                      }

                      if(input::get('case_hege')){
                        $map['case_hege'] = input::get('case_hege');
                       
                      }

                      if(input::get('is_punish') != 3){
                        $map['is_punish'] = input::get('is_punish');
                        
                      }

                      if(input::get('is_delay') != 3){
                        $map['is_delay'] = input::get('is_delay');
                      }

                      

                    

                      $re = DB::table('cases')->where($map)->orderBy('case_id','desc')->paginate(10);
                      $count = DB::table('cases')->where($map)->count();

                      $get = '1';
                      return view('admin.case.zhcase',['re'=>$re,'count'=>$count,'get'=>$get,'units'=>$units]);
                  }else{
                       $get = '0';
                       return view('admin.case.zhcase',['get'=>$get,'units'=>$units]);
                  }
                
            }


            //不合格单位列表
            public function buhege(){
             $map = array(
                  'jiancha.status' => 2,
                  'jiancha.is_case' => 0,
                  'jiancha.is_del' => 0,
                );

              $un = DB::table('jiancha')->where($map)->join('units', 'units.id', '=', 'jiancha.unit_id')->select( 'jiancha.status','jiancha.is_case','jiancha.is_del','jiancha.created_at','jiancha.unit_id','jiancha.id','units.name')->paginate(10);

          
              return view('admin.case.buhege',['un'=>$un]);
            }

            //处罚详情
            public function cfxq($id,request $request){

                $un = DB::table('case_chufa')->where('case_id',$id)->join('admin_users', 'case_chufa.send_uid', '=', 'admin_users.id')->select('case_chufa.*', 'admin_users.name')->first();

                return view('admin.case.cfxq',['un'=>$un]);
            }




            //查看流程图
            public function liu($id,Request $request){

              $re = DB::table('cases')->where('case_id',$id)->orderBy('case_id','desc')->first();

              return view('admin.case.liu',['re'=>$re]);
            }


             //测试
            public function ceshi($id,Request $request){
              return view('admin.case.ceshi');
            }


            public function uploads(){

                     $data['img'] = $_POST['img'];
                     $re =  DB::table('ceshi')->insert($data);
                     $base64 = $_POST['img'];


                       //获取扩告知通知书展名
                // $cont =  $file->getClientOriginalName();
                // $tmpName = $file ->getFileName();
                // $extension = $file -> getClientOriginalExtension();
                // $filedir="storage/uploads/"; //2、定义图片上传路径
                // $newImagesName=md5(time()).random_int(5,5).".".$extension;
                // $file->move($filedir,$newImagesName);

                     $url = explode(',', $base64);
                    
                     $paths = "./storage/uploads/";
                     $prefix='hj_';
                     $output_file = $prefix.time().rand(100,999).'.jpg';
                     $path = $paths.$output_file;
                     $a = file_put_contents($path, base64_decode($url[1]));//返回的是字节数

                     $result = array('message' =>  $a);
                     echo json_encode($result,TRUE);
                     exit();
                  
            }

































}
